<!DOCTYPE html>
<html>
<meta charset="utf-8">
<#include "/common/base_include.ftl"/>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div id="exampleToolbar" role="group">
                    <button type="button" class="btn  btn-primary"
                            onclick="batchCode()">
                        <i class="" aria-hidden="true"></i>批量生成
                    </button>
                    <button type="button" class="btn  btn-success"
                            onclick="edit()">
                        <i class="" aria-hidden="true"></i>生成策略
                    </button>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">  </table>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var prefix = "/common/generator";
    $(function () {
        load();
    });

    function load() {
        $('#exampleTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/list", // 服务器数据的加载地址
            showRefresh: true,
            showToggle: true,
            showColumns: true,
            iconSize: 'outline',
            toolbar: '#exampleToolbar',
            striped: true,
            dataType: "json",
            pagination: true,
            singleSelect: false,
            pageSize: 10,
            pageNumber: 1,
            search: true,
            showColumns: true,
            sidePagination: "client",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'tableName', // 列字段名
                    title: '表名称' // 列标题
                },
                {
                    field: 'engine',
                    title: 'engine'
                },
                {
                    field: 'tableComment',
                    title: '表描述'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn btn-primary btn-sm" href="#" mce_href="#" title="生成代码" onclick="code(\''
                            + row.tableName
                            + '\')"><i class="fa fa-code"></i></a> ';
                        return e;
                    }
                }],
            onLoadSuccess: function (data) {
                if(data.code==0){
                    $("#" + tableId).bootstrapTable("load", data.content);
                }else{
                    layer.msg(data.msg);
                }
            }
        });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function code(tableName) {
        location.href = prefix + "/code/" + tableName;
    }

    function batchCode() {
        var rows = $('#exampleTable').bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
        if (rows.length == 0) {
            layer.msg("请选择要生成代码的表");
            return;
        }
        var tables = new Array();
        // 遍历所有选择的行数据，取每条数据对应的ID
        $.each(rows, function (i, row) {
            tables[i] = row['tableName'];
        });
        location.href = prefix + "/batchCode?tables=" + JSON.stringify(tables).replace('[', '%5B').replace(']', '%5D');
    }

    function edit() {
        layer_open_1(prefix + '/edit','编辑',function (index, layero) {
            current_index=index;
            $(layero).find('form').submit();
        })
    }
</script>
</html>